package com.fcy.teamwork.security.environment.checknode

import android.content.Context
import com.fcy.teamwork.base.log
import com.fcy.teamwork.security.environment.CommandUtil
import com.fcy.teamwork.security.environment.SecurityCheckNode
import java.io.File

class RootCheck : SecurityCheckNode {

    override fun isSecurity(context: Context?): Boolean {
        val res = checkProperty() || isSUExist()
        if (res) log("root权限检测未通过")
        return !res
    }

    private fun checkProperty(): Boolean {
        val property = CommandUtil.getSingleInstance().getProperty("ro.secure")
        return property == "0"
    }

    private fun isSUExist(): Boolean {
        arrayOf(
            "/sbin/su",
            "/system/bin/su",
            "/system/xbin/su",
            "/data/local/xbin/su",
            "/data/local/bin/su",
            "/system/sd/xbin/su",
            "/system/bin/failsafe/su",
            "/data/local/su"
        ).forEach {
            if (File(it).exists())
                return true
        }
        return false
    }
}